import { createBrowserRouter, Navigate } from 'react-router-dom'
import MainLayout from '@/layouts/MainLayout'
import Login from '@/pages/Login'
import Dashboard from '@/pages/Dashboard'
import BookManagement from '@/pages/Reading/BookManagement'
import CategoryManagement from '@/pages/Reading/CategoryManagement'
import ReadingRecords from '@/pages/Reading/ReadingRecords'
import ReadingProgress from '@/pages/Reading/ReadingProgress'
import BorrowManagement from '@/pages/Reading/BorrowManagement'
import ReaderList from '@/pages/Readers/ReaderList'
import ReaderGroups from '@/pages/Readers/ReaderGroups'
import UserList from '@/pages/Users/UserList'
import PermissionManagement from '@/pages/Users/PermissionManagement'
import ReadingStatistics from '@/pages/Analytics/ReadingStatistics'
import UserBehavior from '@/pages/Analytics/UserBehavior'
import PopularContent from '@/pages/Analytics/PopularContent'
import DataReports from '@/pages/Analytics/DataReports'
import NoteManagement from '@/pages/Content/NoteManagement'
import ReviewManagement from '@/pages/Content/ReviewManagement'
import CommentManagement from '@/pages/Content/CommentManagement'
import Notifications from '@/pages/Notifications'
import Profile from '@/pages/Profile'
import AITools from '@/pages/AITools'
import SystemConfig from '@/pages/System/SystemConfig'
import DataBackup from '@/pages/System/DataBackup'
import OperationLogs from '@/pages/System/OperationLogs'
import SecuritySettings from '@/pages/System/SecuritySettings'
import ScheduledTasks from '@/pages/Automation/ScheduledTasks'
import Workflows from '@/pages/Automation/Workflows'
import NotFound from '@/pages/NotFound'

const router = createBrowserRouter(
  [
    {
      path: '/login',
      element: <Login />,
    },
    {
      path: '/',
      element: <MainLayout />,
      children: [
        {
          index: true,
          element: <Navigate to="/dashboard" replace />,
        },
        {
          path: 'dashboard',
          element: <Dashboard />,
        },
        {
          path: 'reading/books',
          element: <BookManagement />,
        },
        {
          path: 'reading/categories',
          element: <CategoryManagement />,
        },
        {
          path: 'reading/records',
          element: <ReadingRecords />,
        },
        {
          path: 'reading/progress',
          element: <ReadingProgress />,
        },
        {
          path: 'reading/borrow',
          element: <BorrowManagement />,
        },
        {
          path: 'readers/list',
          element: <ReaderList />,
        },
        {
          path: 'readers/groups',
          element: <ReaderGroups />,
        },
        {
          path: 'users/list',
          element: <UserList />,
        },
        {
          path: 'users/permissions',
          element: <PermissionManagement />,
        },
        {
          path: 'analytics/reading',
          element: <ReadingStatistics />,
        },
        {
          path: 'analytics/user-behavior',
          element: <UserBehavior />,
        },
        {
          path: 'analytics/popular',
          element: <PopularContent />,
        },
        {
          path: 'analytics/reports',
          element: <DataReports />,
        },
        {
          path: 'content/notes',
          element: <NoteManagement />,
        },
        {
          path: 'content/reviews',
          element: <ReviewManagement />,
        },
        {
          path: 'content/comments',
          element: <CommentManagement />,
        },
        {
          path: 'notifications',
          element: <Notifications />,
        },
        {
          path: 'profile',
          element: <Profile />,
        },
        {
          path: 'ai-tools',
          element: <AITools />,
        },
        {
          path: 'automation/tasks',
          element: <ScheduledTasks />,
        },
        {
          path: 'automation/workflows',
          element: <Workflows />,
        },
        {
          path: 'system/config',
          element: <SystemConfig />,
        },
        {
          path: 'system/backup',
          element: <DataBackup />,
        },
        {
          path: 'system/logs',
          element: <OperationLogs />,
        },
        {
          path: 'system/security',
          element: <SecuritySettings />,
        },
      ],
    },
    {
      path: '*',
      element: <NotFound />,
    },
  ],
  {
    future: {
      v7_startTransition: true,
      v7_relativeSplatPath: true,
      v7_fetcherPersist: true,
      v7_normalizeFormMethod: true,
      v7_partialHydration: true,
      v7_skipActionErrorRevalidation: true,
    },
  }
)

export default router
